/*   1:    */ package com.atomikos.beans;
/*   2:    */ 
/*   3:    */ import com.atomikos.swing.PropertiesPanel;
/*   4:    */ import com.atomikos.swing.PropertiesTableModel;
/*   5:    */ import com.atomikos.swing.PropertyListener;
/*   6:    */ import java.awt.Component;
/*   7:    */ import java.beans.PropertyEditor;
/*   8:    */ import java.lang.reflect.Array;
/*   9:    */ import java.util.Vector;
/*  10:    */ import javax.swing.JCheckBox;
/*  11:    */ import javax.swing.JOptionPane;
/*  12:    */ import javax.swing.JPanel;
/*  13:    */ import javax.swing.JTextField;
/*  14:    */ 
/*  15:    */ public class TableComponent
/*  16:    */   extends AbstractPropertyEditorComponent
/*  17:    */   implements PropertyListener
/*  18:    */ {
/*  19:    */   private Vector data_;
/*  20:    */   private PropertiesPanel panel_;
/*  21:    */   private IndexedProperty property_;
/*  22:    */   
/*  23:    */   private static Object constructNewObject(Class clazz)
/*  24:    */     throws PropertyException
/*  25:    */   {
/*  26: 68 */     Object ret = null;
/*  27: 69 */     JPanel panel = new JPanel();
/*  28: 70 */     JTextField text = null;
/*  29: 71 */     JCheckBox checkbox = null;
/*  30: 72 */     Class wrapperClass = PrimitiveClasses.getWrapperClass(clazz);
/*  31: 73 */     if ((wrapperClass == null) && (!clazz.equals(String.class))) {
/*  32: 74 */       throw new PropertyException("Not a supported class: " + clazz.getName(), null);
/*  33:    */     }
/*  34: 77 */     if ((wrapperClass != null) && (wrapperClass.equals(Boolean.class)))
/*  35:    */     {
/*  36: 79 */       checkbox = new JCheckBox("Check if true", false);
/*  37: 80 */       panel.add(checkbox);
/*  38:    */     }
/*  39:    */     else
/*  40:    */     {
/*  41: 84 */       text = new JTextField("Enter value");
/*  42: 85 */       panel.add(text);
/*  43:    */     }
/*  44: 87 */     int answer = JOptionPane.showConfirmDialog(null, panel, "New Element Property", 2, -1);
/*  45: 91 */     if (answer == 0) {
/*  46: 92 */       if (checkbox != null) {
/*  47: 93 */         ret = new Boolean(checkbox.isSelected()).toString();
/*  48:    */       } else {
/*  49: 96 */         ret = text.getText();
/*  50:    */       }
/*  51:    */     }
/*  52:100 */     return ret;
/*  53:    */   }
/*  54:    */   
/*  55:    */   public TableComponent(IndexedProperty property)
/*  56:    */     throws PropertyException
/*  57:    */   {
/*  58:108 */     this.property_ = property;
/*  59:109 */     Object[] data = (Object[])property.getValue();
/*  60:110 */     this.data_ = new Vector();
/*  61:111 */     for (int i = 0; i < data.length; i++) {
/*  62:112 */       this.data_.addElement(data[i]);
/*  63:    */     }
/*  64:114 */     IndexedPropertyTableModel table = new IndexedPropertyTableModel(this.data_, property.getName());
/*  65:    */     
/*  66:116 */     this.panel_ = new PropertiesPanel(table, false);
/*  67:117 */     this.panel_.getPanel().setToolTipText(property.getDescription());
/*  68:118 */     this.panel_.addPropertyListener(this);
/*  69:    */   }
/*  70:    */   
/*  71:    */   public Component getComponent()
/*  72:    */   {
/*  73:123 */     return this.panel_.getPanel();
/*  74:    */   }
/*  75:    */   
/*  76:    */   public void newProperty(PropertiesTableModel table)
/*  77:    */   {
/*  78:128 */     Object object = null;
/*  79:    */     try
/*  80:    */     {
/*  81:130 */       object = constructNewObject(this.property_.getIndexedType());
/*  82:    */     }
/*  83:    */     catch (PropertyException pe)
/*  84:    */     {
/*  85:134 */       throw new RuntimeException(pe.getMessage());
/*  86:    */     }
/*  87:136 */     if (object != null)
/*  88:    */     {
/*  89:137 */       this.data_.addElement(object);
/*  90:138 */       table.rowInserted();
/*  91:139 */       Object value = Array.newInstance(this.property_.getIndexedType(), this.data_.size());
/*  92:140 */       getPropertyEditor().setValue(value);
/*  93:    */     }
/*  94:    */   }
/*  95:    */   
/*  96:    */   public void deleteProperty(PropertiesTableModel table, int index)
/*  97:    */   {
/*  98:146 */     Object toDelete = this.data_.elementAt(index);
/*  99:147 */     this.data_.remove(toDelete);
/* 100:148 */     table.rowDeleted(index);
/* 101:149 */     Object value = Array.newInstance(this.property_.getIndexedType(), this.data_.size());
/* 102:150 */     getPropertyEditor().setValue(value);
/* 103:    */   }
/* 104:    */   
/* 105:    */   public void editProperty(PropertiesTableModel table, int index)
/* 106:    */   {
/* 107:156 */     JOptionPane.showMessageDialog(null, "To edit, please delete and create a new value...");
/* 108:    */   }
/* 109:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.beans.TableComponent
 * JD-Core Version:    0.7.0.1
 */